package com.da.javatest.leetCode;

/**
 * @author chenlida
 * @date 2019/3/4 14:29
 * @description
 */
public class Code643 {
    public static void main(String[] args) {
        System.out.println(new Code643().findMaxAverage(new int[] {1, 12, -5, -6, 50, 3}, 4));
    }

    public double findMaxAverage(int[] nums, int k) {
        int max = 0;
        for (int i = 0; i < k; i++) {
            max += nums[i];
        }
        int temp = max;
        for (int i = k; i < nums.length; i++) {
            temp -= nums[i - k];
            temp += nums[i];
            max = Math.max(max, temp);
        }
        return (double)max / k;
    }
}
